import requests
import time

class GCD_LCM_Client:
    def __init__(self, base_url="http://localhost:8001"):
        self.base_url = base_url
    
    def compute(self, a: int, b: int) -> dict:
        """计算GCD和LCM"""
        try:
            response = requests.post(
                f"{self.base_url}/gcd_lcm",
                json={
                    "a": a,
                    "b": b
                },
                timeout=3.0
            )
            response.raise_for_status()
            return response.json()
        except requests.exceptions.RequestException as e:
            print(f"请求失败: {str(e)}")
            raise

def run_demo():
    client = GCD_LCM_Client()
    
    test_cases = [
        (48, 18),
        (1071, 462),
        (25, 35),
        (0, 10)
    ]
    
    print("GCD和LCM计算演示")
    print("=" * 40)
    
    for a, b in test_cases:
        print(f"计算 {a} 和 {b} 的GCD和LCM")
        start = time.time()
        result = client.compute(a, b)
        elapsed = time.time() - start
        
        print(f"GCD: {result['gcd']}")
        print(f"LCM: {result['lcm']}")
        print(f"耗时: {elapsed:.6f}秒\n")

if __name__ == "__main__":
    run_demo()